using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using EcsSiteDSTableAdapters;
using System.ComponentModel;
namespace SiteECSWeb
{
    [DataObject]
    public class InquiriesBLL
    {
        private InquiriesTableAdapter _InquiriesTableAdapter = null;

        protected InquiriesTableAdapter InquiriesAdapter
        {
            get
            {
                if (_InquiriesTableAdapter == null)
                {
                    _InquiriesTableAdapter = new InquiriesTableAdapter();
                }
                return _InquiriesTableAdapter;
            }
        }


        #region SelectInquiry 
        [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
        public EcsSiteDS.InquiriesDataTable GetALLInquiries()
        {
            return InquiriesAdapter.GetInquiriesRowRankData();
        }


        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.InquiriesDataTable GetALLInquiriesByID(int inquir_id)
        {
            return InquiriesAdapter.GetInquiriesDataByInquirId(inquir_id);
        }

        //[DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        //public EcsSiteDS.InquiriesDataTable GetPublishInquiriesWithDateAnswer()
        //{
        //    return InquiriesAdapter.GetPublishInquiriesDataWithInquirData();
        //}

        #endregion

        #region InsertInquiry
        [DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
        public bool  AddInquiry(string Inquir_name, 
            string Inquir_Persname, string Inquir_PersPhone, 
            string Inquir_PersFax, string Inquir_PersEmail, 
            string Inquir_Desc, string Inquir_Answer,
            DateTime? Inquir_DateAnswer, int Inquir_Typ, bool Inquir_Published, string Inquir_Published_Nm)
        {
            EcsSiteDS.InquiriesDataTable InquiryTable = new EcsSiteDS.InquiriesDataTable();
            EcsSiteDS.InquiriesRow InquiryRow = InquiryTable.NewInquiriesRow();

            if (Inquir_DateAnswer == null) InquiryRow.SetInquir_DateAnswerNull(); else InquiryRow.Inquir_DateAnswer = Inquir_DateAnswer.Value;
            if (string.IsNullOrEmpty(Inquir_Answer)) InquiryRow.SetInquir_AnswerNull(); else InquiryRow.Inquir_Answer = Inquir_Answer;            
            if (string.IsNullOrEmpty(Inquir_PersFax)) InquiryRow.SetInquir_PersFaxNull(); else InquiryRow.Inquir_PersFax = Inquir_PersFax;
            if (string.IsNullOrEmpty(Inquir_PersPhone)) InquiryRow.SetInquir_PersPhoneNull(); else InquiryRow.Inquir_PersPhone = Inquir_PersPhone;
            if (string.IsNullOrEmpty(Inquir_Published_Nm)) InquiryRow.SetInquir_Published_NmNull(); else InquiryRow.Inquir_Published_Nm = Inquir_Published_Nm;
            
            
            InquiryRow.Inquir_name = Inquir_name;
            InquiryRow.Inquir_Persname = Inquir_Persname;
            InquiryRow.Inquir_PersEmail = Inquir_PersEmail;
            InquiryRow.Inquir_Desc = Inquir_Desc;
            InquiryRow.Inquir_DateIn = DateTime.UtcNow;
            InquiryRow.Inquir_Typ = Inquir_Typ;
            InquiryRow.Inquir_Published = Inquir_Published;

            InquiryTable.AddInquiriesRow(InquiryRow);

            int rowsAffected = InquiriesAdapter.Update(InquiryTable);
            
            return rowsAffected == 1;

        }

        #endregion

        #region UpdateInquiry

        [DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
        public bool UpdateInquiry(string Inquir_name,
            string Inquir_Persname, string Inquir_PersPhone,
            string Inquir_PersFax, string Inquir_PersEmail,
            string Inquir_Desc, string Inquir_Answer, DateTime Inquir_DateIn,
            DateTime? Inquir_DateAnswer, int Inquir_Typ, bool Inquir_Published,
            string Inquir_Published_Nm, int Inquir_id)
        {

            EcsSiteDS.InquiriesDataTable InquiryTable =
                InquiriesAdapter.GetInquiriesDataByInquirId(Inquir_id);
            if (InquiryTable.Count == 0)
            {
                return false;
            }

            EcsSiteDS.InquiriesRow InquiryRow = InquiryTable[0];

            if (Inquir_DateAnswer == null) InquiryRow.SetInquir_DateAnswerNull(); else InquiryRow.Inquir_DateAnswer = Inquir_DateAnswer.Value;
            if (string.IsNullOrEmpty(Inquir_Answer)) InquiryRow.SetInquir_AnswerNull(); else InquiryRow.Inquir_Answer = Inquir_Answer;
            if (string.IsNullOrEmpty(Inquir_PersFax)) InquiryRow.SetInquir_PersFaxNull(); else InquiryRow.Inquir_PersFax = Inquir_PersFax;
            if (string.IsNullOrEmpty(Inquir_PersPhone)) InquiryRow.SetInquir_PersPhoneNull(); else InquiryRow.Inquir_PersPhone = Inquir_PersPhone;
            if (string.IsNullOrEmpty(Inquir_Published_Nm)) InquiryRow.SetInquir_Published_NmNull(); else InquiryRow.Inquir_Published_Nm = Inquir_Published_Nm;
            
            InquiryRow.Inquir_name = Inquir_name;
            InquiryRow.Inquir_Persname = Inquir_Persname;
            InquiryRow.Inquir_PersEmail = Inquir_PersEmail;
            InquiryRow.Inquir_Desc = Inquir_Desc;
            InquiryRow.Inquir_DateIn = Inquir_DateIn;
            InquiryRow.Inquir_Typ = Inquir_Typ;
            InquiryRow.Inquir_Published = Inquir_Published;

            int rowsAffected = InquiriesAdapter.Update(InquiryTable);

            return rowsAffected == 1;
        }
        [DataObjectMethodAttribute(DataObjectMethodType.Update, false)]
        public bool UpdateInquiry(string Inquir_Answer, DateTime? Inquir_DateAnswer,
            bool Inquir_Published,
            string Inquir_Published_Nm, int Inquir_id)
        {

            EcsSiteDS.InquiriesDataTable InquiryTable =
                InquiriesAdapter.GetInquiriesDataByInquirId(Inquir_id);
            if (InquiryTable.Count == 0)
            {
                return false;
            }

            EcsSiteDS.InquiriesRow InquiryRow = InquiryTable[0];

            if (Inquir_DateAnswer == null) InquiryRow.SetInquir_DateAnswerNull(); else InquiryRow.Inquir_DateAnswer = Inquir_DateAnswer.Value;
            if (string.IsNullOrEmpty(Inquir_Answer)) InquiryRow.SetInquir_AnswerNull(); else InquiryRow.Inquir_Answer = Inquir_Answer;
            if (string.IsNullOrEmpty(Inquir_Published_Nm)) InquiryRow.SetInquir_Published_NmNull(); else InquiryRow.Inquir_Published_Nm = Inquir_Published_Nm;
            
            InquiryRow.Inquir_Published = Inquir_Published;

            int rowsAffected = InquiriesAdapter.Update(InquiryTable);

            return rowsAffected == 1;
        }


        #endregion

        #region DeleteInquriy
        [DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
        public bool DeleteInquiry(int Inquir_id)
        {
            int rowsAffected = InquiriesAdapter.Delete(Inquir_id);
            return rowsAffected == 1;
        }
        #endregion
    }
}
